﻿/*
* 
*
* 功 能： N/A
* 类 名： BDGQ
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* 
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;

using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;

namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:BDGQ
	/// </summary>
	public partial class BDGQDAL:IBDGQ
	{
		public BDGQDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string GQID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BDGQ");
			strSql.Append(" where GQID=:GQID ");
			OracleParameter[] parameters = {
					new OracleParameter(":GQID", OracleType.VarChar,30)			};
			parameters[0].Value = GQID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BDGQModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into BDGQ(");
			strSql.Append("GQID,GQMC,GQLX,SSDCBH,QK,SFYTZX,ZXWD,ZXJD)");
			strSql.Append(" values (");
			strSql.Append(":GQID,:GQMC,:GQLX,:SSDCBH,:QK,:SFYTZX,:ZXWD,:ZXJD)");
			OracleParameter[] parameters = {
					new OracleParameter(":GQID", OracleType.VarChar,30),
					new OracleParameter(":GQMC", OracleType.VarChar,30),
					new OracleParameter(":GQLX", OracleType.VarChar,30),
					new OracleParameter(":SSDCBH", OracleType.VarChar,30),
					new OracleParameter(":QK", OracleType.VarChar,30),
					new OracleParameter(":SFYTZX", OracleType.Number,4),
					new OracleParameter(":ZXWD", OracleType.Float,22),
					new OracleParameter(":ZXJD", OracleType.Float,22)};
			parameters[0].Value = model.GQID;
			parameters[1].Value = model.GQMC;
			parameters[2].Value = model.GQLX;
			parameters[3].Value = model.SSDCBH;
			parameters[4].Value = model.QK;
			parameters[5].Value = model.SFYTZX;
			parameters[6].Value = model.ZXWD;
			parameters[7].Value = model.ZXJD;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BDGQModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BDGQ set ");
			strSql.Append("GQMC=:GQMC,");
			strSql.Append("GQLX=:GQLX,");
			strSql.Append("SSDCBH=:SSDCBH,");
			strSql.Append("QK=:QK,");
			strSql.Append("SFYTZX=:SFYTZX,");
			strSql.Append("ZXWD=:ZXWD,");
			strSql.Append("ZXJD=:ZXJD");
			strSql.Append(" where GQID=:GQID ");
			OracleParameter[] parameters = {
					new OracleParameter(":GQMC", OracleType.VarChar,30),
					new OracleParameter(":GQLX", OracleType.VarChar,30),
					new OracleParameter(":SSDCBH", OracleType.VarChar,30),
					new OracleParameter(":QK", OracleType.VarChar,30),
					new OracleParameter(":SFYTZX", OracleType.Number,4),
					new OracleParameter(":ZXWD", OracleType.Float,22),
					new OracleParameter(":ZXJD", OracleType.Float,22),
					new OracleParameter(":GQID", OracleType.VarChar,30)};
			parameters[0].Value = model.GQMC;
			parameters[1].Value = model.GQLX;
			parameters[2].Value = model.SSDCBH;
			parameters[3].Value = model.QK;
			parameters[4].Value = model.SFYTZX;
			parameters[5].Value = model.ZXWD;
			parameters[6].Value = model.ZXJD;
			parameters[7].Value = model.GQID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string GQID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDGQ ");
			strSql.Append(" where GQID=:GQID ");
			OracleParameter[] parameters = {
					new OracleParameter(":GQID", OracleType.VarChar,30)			};
			parameters[0].Value = GQID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string GQIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDGQ ");
			strSql.Append(" where GQID in ("+GQIDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDGQModel GetModel(string GQID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select GQID,GQMC,GQLX,SSDCBH,QK,SFYTZX,ZXWD,ZXJD from BDGQ ");
			strSql.Append(" where GQID=:GQID ");
			OracleParameter[] parameters = {
					new OracleParameter(":GQID", OracleType.VarChar,30)			};
			parameters[0].Value = GQID;

			BDGQModel model=new BDGQModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDGQModel DataRowToModel(DataRow row)
		{
			BDGQModel model=new BDGQModel();
			if (row != null)
			{
				if(row["GQID"]!=null)
				{
					model.GQID=row["GQID"].ToString();
				}
				if(row["GQMC"]!=null)
				{
					model.GQMC=row["GQMC"].ToString();
				}
				if(row["GQLX"]!=null)
				{
					model.GQLX=row["GQLX"].ToString();
				}
				if(row["SSDCBH"]!=null)
				{
					model.SSDCBH=row["SSDCBH"].ToString();
				}
				if(row["QK"]!=null)
				{
					model.QK=row["QK"].ToString();
				}
				if(row["SFYTZX"]!=null && row["SFYTZX"].ToString()!="")
				{
					model.SFYTZX=decimal.Parse(row["SFYTZX"].ToString());
				}
				if(row["ZXWD"]!=null && row["ZXWD"].ToString()!="")
				{
					model.ZXWD=decimal.Parse(row["ZXWD"].ToString());
				}
				if(row["ZXJD"]!=null && row["ZXJD"].ToString()!="")
				{
					model.ZXJD=decimal.Parse(row["ZXJD"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select GQID,GQMC,GQLX,SSDCBH,QK,SFYTZX,ZXWD,ZXJD ");
			strSql.Append(" FROM BDGQ ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BDGQ ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.GQID desc");
			}
			strSql.Append(")AS Row, T.*  from BDGQ T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "BDGQ";
			parameters[1].Value = "GQID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

